﻿namespace CSharpPro._1028;

public class UserService : IUserService
{
    // 泛型集合存储用户对象
    private List<User> _userList = new List<User>();

    public void ShowMainMenu()
    {
        while (true)
        {
            Console.WriteLine("主菜单：1. 登录 2. 注册 3. 退出");
            Console.Write("请输入数字选择功能：");
            string choice = Console.ReadLine().Trim();

            switch (choice)
            {
                case "1":
                    Login();
                    break;
                case "2":
                    Regist();
                    break;
                case "3":
                    Console.WriteLine("退出程序");
                    return;
                default:
                    Console.WriteLine("请输入有效数字");
                    break;
            }
        }
    }

    public void Login()
    {
        Console.Write("请输入用户名：");
        string username = Console.ReadLine().Trim();
        if (string.IsNullOrWhiteSpace(username))
        {
            Console.WriteLine("用户名不可为空");
            return;
        }

        Console.Write("请输入密码：");
        string password = Console.ReadLine().Trim();
        if (string.IsNullOrWhiteSpace(password))
        {
            Console.WriteLine("密码不可为空");
            return;
        }

        // 遍历泛型集合（foreach循环迭代）
        User? targetUser = null;
        foreach (User user in _userList)
        {
            if (user.Username == username)